package common.mq.active;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * Created by dong peng on 2018/1/29.
 */
public class TopicProducer {

    public static void main(String[] args) throws JMSException {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
          ActiveMQConnectionFactory.DEFAULT_USER,
                ActiveMQConnectionFactory.DEFAULT_PASSWORD,
                ActiveMQConnectionFactory.DEFAULT_BROKER_URL
        );

        Connection connection  = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(Boolean.FALSE,Session.CLIENT_ACKNOWLEDGE);

        Destination destination = session.createTopic("topic1");

        MessageProducer producer = session.createProducer(destination);

        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

        for(int i = 0; i< 10000; i++) {
            TextMessage textMessage = session.createTextMessage();
            textMessage.setText("hello topic text");
            producer.send(textMessage);
        }


        connection.close();

    }
}
